package com.mooco.dongba.sys.controller;

import com.mooco.dongba.common.pojo.JsonResult;
import com.mooco.dongba.common.pojo.PageObject;
import com.mooco.dongba.sys.pojo.SysRole;
import com.mooco.dongba.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @RequestMapping("/doFindPageObjects")
    public JsonResult doFindPageObjects(String name, Integer pageCurrent) {
        return new JsonResult(sysRoleService.findPageObjects(name, pageCurrent));
    }

    @PostMapping("/doDeleteObject")
    public JsonResult doDeleteObject(Long id) {
        sysRoleService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    @PostMapping("/doSaveObject")
    public JsonResult doSaveObject(SysRole entity, Integer[] menuIds) {
        sysRoleService.saveObject(entity, menuIds);
        return new JsonResult("save ok");
    }

    @GetMapping("/doFindObjectById")
    public JsonResult doFindObjectById(Long id) {
        return new JsonResult(sysRoleService.FindObjectById(id));
    }

    @PostMapping("/doUpdateObject")
    public JsonResult doUpdateObject(SysRole entity, Integer[] menuIds) {
        sysRoleService.updateObject(entity, menuIds);
        return new JsonResult("update ok");
    }

    @RequestMapping("/doFindRoles")
    public JsonResult doFindRoles() {
        return new JsonResult(sysRoleService.findObjects());
    }
}
